package command

import (
	"octopus/hextech/message"
	"octopus/user/dto"
	"octopus/user/model/service"

	"github.com/gin-gonic/gin"
)

func Login(ctx *gin.Context) {
	args := &dto.LoginRequest{}

	err := ctx.ShouldBindJSON(args)
	if err != nil {
		message.FailedWithMsg(ctx, err.Error(), err)
		return
	}

	if err := service.NewUserService(ctx).Login(args); err != nil {
		message.FailedWithMsg(ctx, err.Error(), err)
		return
	}

	message.Success(ctx, struct{}{})
	return
}

func CreateUser(ctx *gin.Context) {
	args := &dto.CreateUserRequest{}

	err := ctx.ShouldBindJSON(args)
	if err != nil {
		message.FailedWithMsg(ctx, err.Error(), err)
		return
	}

	if err := service.NewUserService(ctx).Create(args); err != nil {
		message.FailedWithMsg(ctx, err.Error(), err)
		return
	}

	message.Success(ctx, struct{}{})
	return
}
